//
//  ZYMyOrderCarViewController.m
//  DistributorAB
//
//  Created by 李 on 2019/11/8.
//  Copyright © 2019年 主事丫环. All rights reserved.
//
#import "ZYMyOrderCarViewController.h"

#import "ZMyOrderCarStoreCell.h"//店铺cell
#import "ZMyOrderCarShopOrderCell.h"//产品cell
#import "ZMyOrderCarBottomView.h"//底部view
#import "ZMyOrderCarOrderModel.h"

#import "BBuyNowShopStoreVC.h"//店铺
#import "BBuyNowShopDetailVC.h"//配件产品详情
#import "ZSubmitMyOrderVC.h"//提交预订单

@interface ZYMyOrderCarViewController () <UITableViewDelegate,UITableViewDataSource,ZMyOrderCarStoreCellDelegate,ZMyOrderCarShopOrderCellDelegate,ZMyOrderCarBottomViewDelegate>
@property (nonatomic, strong) UITableView *mytableView;
@property (nonatomic, strong) NSMutableArray *myStoreSouce;

@property (nonatomic, strong) UIView *tabFootView;
@property (nonatomic, strong) UIView *bgViewsec;
@property (nonatomic, strong) UIView *bgViewsecDele;

@property (nonatomic, assign) BOOL allChose;
@property (nonatomic, strong) UIButton *allSelBtn;//全选按钮
@property (nonatomic, strong) UIButton *orderNowBtn;//预订按钮
@property (nonatomic, strong) UIButton *deleteBtn;//删除按钮
@end

@implementation ZYMyOrderCarViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"预订车";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    [self.rightbutton setTitle:@"管理" forState:(UIControlStateNormal)];
    
    _myStoreSouce = [NSMutableArray array];
    
    [self setupViewAction];
    
    [MBProgressHUD showHUDAddedTo:self.view msg:@"数据加载中" animated:YES];
    [self requestData];
    
    //通知监听
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestData) name:USER_ADD_ORDER_SUCCESS object:nil];
}
#pragma mark - 管理按钮
- (void)managerMyOrderListAction:(NSInteger)actionType{
    if (actionType == 1) {
        //完成 - 进行删除操作
        self.deleteBtn.hidden = NO;
        self.orderNowBtn.hidden = YES;
    }else{
        //管理 - 进行立即预订操作
        self.deleteBtn.hidden = YES;
        self.orderNowBtn.hidden = NO;
    }
    self.allChose = NO;
    self.allSelBtn.selected = NO;
    [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.isSelected = NO;
        [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.isOrderSelected = NO;
        }];
    }];
    [_mytableView reloadData];
}
#pragma mark - 界面布局
- (void)setupViewAction{
    _mytableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height - kNaviHeight - TabbarSafeBottomMargin - 56-60) style:UITableViewStylePlain];
    _mytableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _mytableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    [self.view addSubview:_mytableView];
    _mytableView.delegate = self;
    _mytableView.dataSource = self;
    
    KKTableViewNoDataView *viewPlaceHolder = [[KKTableViewNoDataView alloc] initWithFrame:CGRectMake((kScreen_Width - 100) / 2.0, (kScreen_Height - kNaviHeight - TabbarSafeBottomMargin - 56-60-72) / 2.0, 100, 72) image:imgname(@"tableviewPlaseholder") viewClick:^{}];
    _mytableView.placeHolderView = viewPlaceHolder;
    
    [_mytableView registerClass:[ZMyOrderCarStoreCell class] forCellReuseIdentifier:NSStringFromClass([ZMyOrderCarStoreCell class])];
    [_mytableView registerClass:[ZMyOrderCarShopOrderCell class] forCellReuseIdentifier:NSStringFromClass([ZMyOrderCarShopOrderCell class])];
    
    UIView *bottomView = [[UIView alloc] init];
    bottomView.frame = CGRectMake(0, KHEIGHT - 60 - kNaviHeight - 56, KWIDTH, 56);
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    
    UILabel *line = [[UILabel alloc] init];
    line.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    line.frame = CGRectMake(0, 0, KWIDTH, 1);
    [bottomView addSubview:line];
    
    //全选按钮
    UIButton *allSelBtn = [[UIButton alloc] init];
    allSelBtn.backgroundColor = [UIColor whiteColor];
    allSelBtn.frame = CGRectMake(10, 8, 90, 40);
    [allSelBtn setImage:[UIImage imageNamed:@"cycle_normal_gray_icon"] forState:UIControlStateNormal];
    [allSelBtn setImage:[UIImage imageNamed:@"cycle_selected_green_icon"] forState:UIControlStateSelected];
    [allSelBtn setTitle:@"全选" forState:UIControlStateNormal];
    allSelBtn.titleLabel.font = FontSize(14);
    [allSelBtn setTitleColor:[UIColor colorWithHexString:@"#484848"] forState:UIControlStateNormal];
    [allSelBtn addTarget:self action:@selector(bottomSelBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:allSelBtn];
    self.allSelBtn = allSelBtn;
    
    //删除按钮
    UIButton *deleteBtn = [[UIButton alloc] init];
    deleteBtn.backgroundColor = [UIColor whiteColor];
    deleteBtn.frame = CGRectMake(bottomView.right-187, 8, 169, 42);
    [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    deleteBtn.titleLabel.font = FontSize(14);
    deleteBtn.layer.borderColor = [UIColor redColor].CGColor;
    deleteBtn.layer.borderWidth = 1;
    deleteBtn.layer.cornerRadius = 21;
    deleteBtn.layer.masksToBounds = YES;
    [deleteBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:deleteBtn];
    self.deleteBtn = deleteBtn;
    
    //立即预订按钮
    UIButton *orderNowBtn = [[UIButton alloc] init];
    orderNowBtn.backgroundColor = [UIColor colorWithHexString:@"#70BE68"];
    orderNowBtn.frame = CGRectMake(bottomView.right-187, 8, 169, 42);
    [orderNowBtn setTitle:@"立即预订" forState:UIControlStateNormal];
    orderNowBtn.titleLabel.font = FontSize(14);
    orderNowBtn.layer.cornerRadius = 21;
    orderNowBtn.layer.masksToBounds = YES;
    [orderNowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [orderNowBtn addTarget:self action:@selector(orderNowBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:orderNowBtn];
    self.orderNowBtn = orderNowBtn;
}
#pragma mark - 底部功能按钮
- (void)bottomSelBtnAction:(UIButton *)button {
    self.allChose = !self.allChose;
    if (self.allChose) {
        //全选
        self.allSelBtn.selected = YES;
        [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.isSelected = YES;
            [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.isOrderSelected = YES;
            }];
        }];
    } else {
        //取消全选
        self.allSelBtn.selected = NO;;
        [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.isSelected = NO;
            [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.isOrderSelected = NO;
            }];
        }];
    }
    [_mytableView reloadData];
}

//立即预订按钮 点击事件处理
- (void)orderNowBtnAction:(UIButton *)button {
    [self managerOrderCarRequestDataWithType:1];
    NSLog(@"您点击了 底部的 立即预订 按钮");
}

//删除按钮 点击事件处理
- (void)deleteBtnAction:(UIButton *)button {
   
    __block NSString *orderIDStr = @"";//订单ID拼接
    [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull objPart, NSUInteger idx, BOOL * _Nonnull stop) {
            if (objPart.isOrderSelected) {
                orderIDStr = [orderIDStr stringByAppendingString: orderIDStr.length > 0 ? [NSString stringWithFormat:@",%@",objPart.Id] : objPart.Id];
            }
        }];
    }];
    if (orderIDStr.length==0) {
          ShowToastWithText(@"请选择预订的产品");
          return;
    }
    //弹出提示框
    [[UIApplication sharedApplication].keyWindow addSubview:self.bgViewsecDele];
    
}
#pragma mark - 删除我的预订弹窗交互
//我在想想
-(void)tleftBtnAction:(UIButton *)but{
    [_bgViewsecDele removeFromSuperview];
}
//删除
-(void)trightBtnAction:(UIButton *)but{
    [_bgViewsecDele removeFromSuperview];
    [self managerOrderCarRequestDataWithType:2];
}
#pragma mark - 删除弹窗
- (UIView *)bgViewsecDele{
    if (!_bgViewsecDele) {
        UIWindow *window = [[UIApplication sharedApplication].delegate window];
        _bgViewsecDele = [[UIView alloc]init];
        _bgViewsecDele.frame = window.bounds;
        _bgViewsecDele.backgroundColor = kColorWithHex(0xb1b0af);
        UIView *whiteBGView = [[UIView alloc]init];
        whiteBGView.backgroundColor = [UIColor whiteColor];
        whiteBGView.layer.masksToBounds = YES;
        whiteBGView.layer.cornerRadius = 6;
        [_bgViewsecDele addSubview:whiteBGView];
        [whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.offset(0);
            make.height.offset(240);
            make.left.offset(22);
            make.right.offset(-22);
        }];
        
        UIImageView *upImage = [[UIImageView alloc]initWithFrame:CGRectMake(KWIDTH/2-22-30, 34, 60, 60)];
        upImage.layer.masksToBounds = YES;
        upImage.layer.cornerRadius = 20;
        [whiteBGView addSubview:upImage];
        upImage.image = [UIImage imageNamed:@"tipImage"];
        
        UILabel *UpLable = [[UILabel alloc]initWithFrame:CGRectMake(0, upImage.bottom +19, KWIDTH-44, 21)];
        [whiteBGView addSubview:UpLable];
        UpLable.font = FontSize(16);
        UpLable.textColor = [UIColor colorWithHexString:@"#333333"];
        UpLable.textAlignment =  NSTextAlignmentCenter;
        UpLable.text = @"确认删除?";
        
        UIButton *leftButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [leftButton setTitle:@"取消" forState:(UIControlStateNormal)];
        [leftButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [leftButton setBackgroundColor:[[UIColor colorWithHexString:@"#70BE68"] colorWithAlphaComponent:1]];
        leftButton.layer.masksToBounds = YES;
        leftButton.layer.cornerRadius = 4;
        leftButton.titleLabel.font = FontSize(14);
        [leftButton addTarget:self action:@selector(tleftBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [whiteBGView addSubview:leftButton];
        [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.offset(36);
            make.left.offset(28);
            make.right.equalTo(whiteBGView.mas_centerX).offset(-13);
            make.bottom.offset(-19);
        }];
        
        UIButton *rightButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [rightButton setTitle:@"确认" forState:(UIControlStateNormal)];
        [rightButton setTitleColor:[UIColor colorWithHexString:@"#70BE68"] forState:(UIControlStateNormal)];
        [rightButton setBackgroundColor:[UIColor whiteColor]];
        rightButton.layer.masksToBounds = YES;
        rightButton.layer.cornerRadius = 4;
        rightButton.layer.borderWidth = 1;
        rightButton.layer.borderColor = [UIColor colorWithHexString:@"#70BE68"].CGColor;
        rightButton.titleLabel.font = FontSize(14);
        [rightButton addTarget:self action:@selector(trightBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [whiteBGView addSubview:rightButton];
        [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.offset(36);
            make.left.equalTo(whiteBGView.mas_centerX).offset(13);
            make.right.offset(-28);
            make.bottom.offset(-19);
        }];
        
    }
    return _bgViewsecDele;
}
#pragma mark - 数据请求
- (void)requestData{
    kWeakSelf;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObjectIfNotNil:@"1" forKey:@"user_type"];
    
    [NetWorkTool POST:myOrderCar param:dict success:^(id dic) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [weakSelf.myStoreSouce removeAllObjects];
        NSArray *orderList = [dic objectForKeyNotNil:@"data"];
        [orderList enumerateObjectsUsingBlock:^(NSDictionary  * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            ZMyOrderCarOrderModel *model = [ZMyOrderCarOrderModel mj_objectWithKeyValues:obj];
            [weakSelf.myStoreSouce addObjectNotNil:model];
        }];
        [weakSelf.mytableView reloadData];
      
        KMyLog(@"预订车有没有数据 %@", dic);
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    } fail:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        ShowToastWithText(@"数据请求失败");
    } needUser:YES];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.myStoreSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    ZMyOrderCarOrderModel *model = [self.myStoreSouce objectAtIndexSafe:section];
    return model.parts.count + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZMyOrderCarOrderModel *model = [self.myStoreSouce objectAtIndexSafe:indexPath.section];
    if (indexPath.row == 0) {
        ZMyOrderCarStoreCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZMyOrderCarStoreCell class]) forIndexPath:indexPath];
        cell.model = model;
        cell.delegate = self;
        cell.indexPath = indexPath;
        return cell;
    }else{
        BShopPartModel *partModel = [model.parts objectAtIndexSafe:indexPath.row - 1];
        ZMyOrderCarShopOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZMyOrderCarShopOrderCell class]) forIndexPath:indexPath];
        cell.partModel = partModel;
        cell.indexPath = indexPath;
        if (indexPath.row == model.parts.count) {
            cell.isRoundBg = YES;
        }else{
            cell.isRoundBg = NO;
        }
        cell.delegate = self;
        return cell;
    }
    return [UITableViewCell new];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ZMyOrderCarOrderModel *model = [self.myStoreSouce objectAtIndexSafe:indexPath.section];
    if (indexPath.row == 0) {
        //进入店铺
        //        BBuyNowShopStoreVC *vc = [BBuyNowShopStoreVC new];
        //        vc.storeID = model.Id;
        //        vc.orderModel = model;
        //        [self.navigationController pushViewController:vc animated:YES];
    }else{
        //进入产品详情
        BBuyNowShopDetailVC *vc = [BBuyNowShopDetailVC new];
        BShopPartModel *partModel = [model.parts objectAtIndexSafe:indexPath.row - 1];
        vc.shopID = partModel.partsId;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return [ZMyOrderCarStoreCell cellHeight];
    }else{
        return [ZMyOrderCarShopOrderCell cellHeight];
    }
}
#pragma mark - ZMyOrderCarStoreCellDelegate
- (void)orderCarStoreCellClick:(NSIndexPath *)indexPath isSelected:(BOOL)isSelected{
    //刷新section
    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:indexPath.section];
    [self.mytableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
    
    [self checkIsAllSelected];
    
}
#pragma mark - ZMyOrderCarShopOrderCellDelegate
//选中按钮点击
- (void)orderCarShopOrderCellClick:(NSIndexPath *)indexPath isSelected:(BOOL)isSelected{
    //刷新cell
    NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
    NSIndexPath *indexZero = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
    
    ZMyOrderCarOrderModel *model = [self.myStoreSouce objectAtIndexSafe:indexPath.section];
    __block NSInteger selectedNumber = 0;
    [model.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.isOrderSelected == YES) {
            selectedNumber++;
        }
    }];
    if (selectedNumber == model.parts.count) {
        //全选
        model.isSelected = YES;
    }else{
        //非全选
        model.isSelected = NO;
    }
    
    [self.mytableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:index,indexZero,nil] withRowAnimation:UITableViewRowAnimationNone];
    
    [self checkIsAllSelected];
}
//检查是否触发了全选
- (void)checkIsAllSelected{
    __block NSInteger selectedSection = 0;
    [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.isSelected) {
            selectedSection++;
        }
    }];
    if (selectedSection == self.myStoreSouce.count) {
        //全选
        self.allSelBtn.selected = YES;
        self.allChose = YES;
    }else{
        self.allSelBtn.selected = NO;
        self.allChose = NO;
    }
}
#pragma mark - ZMyOrderCarBottomViewDelegate
- (void)orderCarBottomViewClick:(ZMyOrderCarBottomViewClickType)clickType{
    if (clickType == ZMyOrderCarBottomViewClickTypeNoneSelected) {
        //取消全选
        [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.isSelected = NO;
            [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.isOrderSelected = NO;
            }];
        }];
        [self.mytableView reloadData];
    }else if (clickType == ZMyOrderCarBottomViewClickTypeSelected){
        //全选
        [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.isSelected = YES;
            [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.isOrderSelected = YES;
            }];
        }];
        [self.mytableView reloadData];
    }else if (clickType == ZMyOrderCarBottomViewClickTypeBuy){
        //我要预订
        [self managerOrderCarRequestDataWithType:1];
    }else if (clickType == ZMyOrderCarBottomViewClickTypeDelete){
        //删除
        [self managerOrderCarRequestDataWithType:2];
    }
}
#pragma mark - 管理预订车接口处理
- (void)managerOrderCarRequestDataWithType:(NSInteger)type{
    __block NSString *orderIDStr = @"";//订单ID拼接
    __block NSString *countStr = @"";//订单数量拼接
    
    [self.myStoreSouce enumerateObjectsUsingBlock:^(ZMyOrderCarOrderModel  * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj.parts enumerateObjectsUsingBlock:^(BShopPartModel * _Nonnull objPart, NSUInteger idx, BOOL * _Nonnull stop) {
            if (objPart.isOrderSelected) {
                orderIDStr = [orderIDStr stringByAppendingString: orderIDStr.length > 0 ? [NSString stringWithFormat:@",%@",objPart.Id] : objPart.Id];
                countStr = [countStr stringByAppendingString: countStr.length > 0 ? [NSString stringWithFormat:@",%@",objPart.count] : objPart.count];
            }
        }];
    }];
    
    if (orderIDStr.length > 0) {
        kWeakSelf;
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setObjectIfNotNil:@(type) forKey:@"type"];
        [dict setObjectIfNotNil:@"1" forKey:@"user_type"];
        [dict setObjectIfNotNil:orderIDStr forKey:@"ids"];
        [dict setObjectIfNotNil:countStr forKey:@"counts"];
        [NetWorkTool POST:managerMyOrderCar param:dict success:^(id dic) {
            if (type == 1) {
                //提交成功
                NSArray *orderList = [dic objectForKeyNotNil:@"data"];
                __block NSMutableArray *submitOrderArray = [NSMutableArray array];
                [orderList enumerateObjectsUsingBlock:^(NSDictionary  * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    ZMyOrderCarOrderModel *model = [ZMyOrderCarOrderModel mj_objectWithKeyValues:obj];
                    [submitOrderArray addObjectNotNil:model];
                }];
                ZSubmitMyOrderVC *vc = [ZSubmitMyOrderVC new];
                vc.submitOrderArray = submitOrderArray;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            } else if (type == 2){
                //删除成功
                [weakSelf requestData];
            }
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        } other:^(id dic) {
            ShowToastWithText(dic[@"msg"]);
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        } fail:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        } needUser:YES];
    } else {
        ShowToastWithText(@"请选择预订的产品");
    }
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end

